package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.HospRecord;
import com.itboye.jinpuyiyuan.bean.InHosBean;
import com.itboye.jinpuyiyuan.bean.LaborRecordBean;
import com.itboye.jinpuyiyuan.bean.RecipeRecordBean;

import java.util.List;

public class MeHosAdapter extends RecyclerView.Adapter<MeHosAdapter.MyViewHolder> {


    private List<HospRecord.Orders> list1;
    private List<RecipeRecordBean.PayListBean> list2;
    private List<LaborRecordBean.Reports.ReportInfo> list3;
    private List<InHosBean.Pat> list4;

    private Context context;
    private int type;
    private OnItemClick onItemClick;

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    /**
     * @param context
     * @param list
     * @param type  1 就诊记录  2处方记录  3 化验记录  4住院记录
     */
    public MeHosAdapter(Context context,List<HospRecord.Orders> list,int type,String name){
           this.context=context;
           this.list1=list;
           this.type=type;
    }
    public MeHosAdapter(Context context,List<RecipeRecordBean.PayListBean> list,int type,float name){
        this.context=context;
        this.list2=list;
        this.type=type;
    }
    public MeHosAdapter(Context context,List<LaborRecordBean.Reports.ReportInfo> list,int type,int name){
        this.context=context;
        this.list3=list;
        this.type=type;
    }
    public MeHosAdapter(Context context,List<InHosBean.Pat> list,int type){
        this.context=context;
        this.list4=list;
        this.type=type;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_mehos, null, false);

        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        switch (type){

            case 1:
                if (position==list1.size()-1){
                    holder.space.setVisibility(View.GONE);
                }
                HospRecord.Orders orders= (HospRecord.Orders) list1.get(position);
                holder.firstName.setText("姓名");
                holder.firstValue.setText(orders.getPat_name());
                holder.twoName.setText("就诊序号");
                holder.twoValue.setText(orders.getClinicid());
                holder.threeName.setText("就诊科室");
                holder.threeValue.setText(orders.getDept_id());
                holder.fourName.setText("就诊医生");
                holder.fourValue.setText(orders.getDoctor_id());

                holder.queryDetail.setVisibility(View.GONE);
                holder.payStatus.setVisibility(View.GONE);
                holder.titleName.setText("就诊信息");
                holder.repTime.setText(orders.getDate());
                break;
            case 2:
                if (position==list2.size()-1){
                    holder.space.setVisibility(View.GONE);
                }
                RecipeRecordBean.PayListBean bean= (RecipeRecordBean.PayListBean) list2.get(position);

                holder.firstName.setText("医生姓名");
                holder.firstValue.setText(bean.getDoctor_name());
                holder.twoName.setText("就诊科室");
                holder.twoValue.setText(bean.getDept_name());
                holder.threeName.setText("收据号");
                holder.threeValue.setText(bean.getReceipt_id());
                holder.fourName.setText("总金额");
                holder.fourValue.setText(Float.parseFloat(bean.getPay_amout())/100+"");

                holder.titleName.setText("处方信息");
                holder.repTime.setText(bean.getReceipt_date());
                holder.queryDetail.setVisibility(View.VISIBLE);
                holder.payStatus.setVisibility(View.VISIBLE);
                if (list2.get(position).getOrder_status().equals("1")){//已付款
                    holder.payStatus.setImageResource(R.drawable.payed);
                }else {//未付款
                    holder.payStatus.setImageResource(R.drawable.topay);
                }
                holder.queryDetail.setText("查看详情");
                holder.queryDetail.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClick.setOnItemClic(position);
                    }
                });
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClick.setOnItemClic(position);
                    }
                });
                break;
            case 3:
                if (position==list3.size()-1){
                    holder.space.setVisibility(View.GONE);
                }
                LaborRecordBean.Reports.ReportInfo info= (LaborRecordBean.Reports.ReportInfo) list3.get(position);
                holder.firstName.setText("检查项目");
                holder.firstValue.setText(info.getItem_name());
                holder.twoName.setText("诊断");
                holder.twoValue.setText(info.getDiagnosis());
                holder.threeName.setText("科室名称");
                holder.threeValue.setText(info.getDept_name());
                holder.fourName.setText("报告类型");
                if ("0".equals(info.getReport_type().trim())){
                    holder.fourValue.setText("普通检验报告");
                }else if ("1".equals(info.getReport_type().trim())){
                    holder.fourValue.setText("药敏检验报告");
                }else if ("2".equals(info.getReport_type().trim())){
                    holder.fourValue.setText("检查报告");
                }

                holder.queryDetail.setVisibility(View.VISIBLE);
                holder.payStatus.setVisibility(View.GONE);
                holder.titleName.setText("化验信息");
                holder.repTime.setText(info.getReport_time());
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClick.setOnItemClic(position);
                    }
                });
                holder.queryDetail.setText("查看详情");
                holder.queryDetail.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClick.setOnItemClic(position);
                    }
                });
                break;
            case 4:
                if (position==list4.size()-1){
                    holder.space.setVisibility(View.GONE);
                }
                InHosBean.Pat pat= (InHosBean.Pat) list4.get(position);

                holder.firstName.setText("姓名");
                holder.firstValue.setText(pat.getPatientname());
                holder.twoName.setText("科室名称");
                holder.twoValue.setText(pat.getDeptname());
                holder.threeName.setText("住院号码");
                holder.threeValue.setText(pat.getPatientno());
                holder.fourName.setText("病人费别名称");
                holder.fourValue.setText(pat.getPatientnature());


                holder.queryDetail.setVisibility(View.VISIBLE);
                holder.payStatus.setVisibility(View.GONE);
                holder.titleName.setText("住院信息");
                holder.repTime.setText(pat.getIndate());
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClick.setOnItemClic(position);
                    }
                });
                holder.queryDetail.setText("查看住院缴费记录");
                holder.queryDetail.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClick.setOnItemClic(position);
                    }
                });
                break;

        }
    }

    @Override
    public int getItemCount() {

        if (type==1){
            return list1.size();
        }else if (type==2){
            return list2.size();
        }else if (type==3){
            return list3.size();
        }else if (type==4){
            return list4.size();
        }else {
            return 0;
        }

    }

//    private List<HospRecord.Orders> list1;
//    private List<RecipeRecordBean.PayListBean> list2;
//    private List<LaborRecordBean.Reports.ReportInfo> list3;
//    private List<InHosBean.Pat> list4;
    public void addData(List<HospRecord.Orders> list1,int type,String name){
        this.list1=list1;
        this.type=type;
        this.notifyDataSetChanged();
    }
    public void addData(List<RecipeRecordBean.PayListBean> list2,int type,float name){
       this.list2=list2;
       this.type=type;
       this.notifyDataSetChanged();
    }
    public void addData(List<LaborRecordBean.Reports.ReportInfo> list3,int type,int name){
        this.list3=list3;
        this.type=type;
        this.notifyDataSetChanged();
    }
    public void addData(List<InHosBean.Pat> list4,int type){
        this.list4=list4;
        this.type=type;
        this.notifyDataSetChanged();
    }
    public class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView titleName,repTime;
        private TextView firstName,twoName,threeName,fourName;
        private TextView firstValue,twoValue,threeValue,fourValue;
        private TextView queryDetail;
        private View itemView;
        private ImageView payStatus;
        private View space;
        public MyViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            firstName=itemView.findViewById(R.id.firstName);
            twoName=itemView.findViewById(R.id.twoName);
            threeName=itemView.findViewById(R.id.threeName);
            fourName=itemView.findViewById(R.id.fourName);
            firstValue=itemView.findViewById(R.id.firstValue);
            twoValue=itemView.findViewById(R.id.twoValue);
            threeValue=itemView.findViewById(R.id.threeValue);
            fourValue=itemView.findViewById(R.id.fourValue);
            titleName=itemView.findViewById(R.id.titleName);
            repTime=itemView.findViewById(R.id.repTime);
            queryDetail=itemView.findViewById(R.id.queryDetail);
            payStatus=itemView.findViewById(R.id.payStatus);
            space=itemView.findViewById(R.id.space);
        }
    }


    public interface OnItemClick{
        void setOnItemClic(int position);
    }
}
